﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using Bitis_KeToanThue_Pro_QuanTri.AccessDatabase;
using Bitis_KeToanThue_Pro_DungChung.Common;

namespace Bitis_KeToanThue_Pro_QuanTri.Form
{
    public partial class frmCapMenuInUser : Telerik.WinControls.UI.RadForm
    {
        CapQuyenMenuChoNguoiDung cq = new CapQuyenMenuChoNguoiDung();
        public static int MaNhom = 0;
        public static string tennhom = "";
        public static int xoakt=0;
        public frmCapMenuInUser()
        {
            InitializeComponent();
            khoitaogridnhomnguoidung();
            khoitaogridnhommenu();
            khoitaogridchuongtrinh();
            khoitaogridvitri();
            //
            loaddulideunhomnguoidung();
            UpdatePanelInfo(this.gridUsersGroup.CurrentRow);
            khoitaoluoicapquyen();
            xoakt = BienHeThong.ht_quyenxoa;
            if (BienHeThong.ht_quyencapnhat == 1)
            {
                btnSave.Enabled = true;
            }
            else
            {
                btnSave.Enabled = false;
            }
            if (BienHeThong.ht_quyenxoa == 1)
            {
                btnResetRole.Enabled = true;
                btnRemove.Enabled = true;
            }
            else
            {
                btnResetRole.Enabled = false;
                btnRemove.Enabled =false;
            }
        }
       
      

      
        private void loadluoicapquyen(int manhom)
        {
            if (radGridView1.RowCount > 0)
            {
                for (int i = radGridView1.RowCount - 1; i >= 0; i--)
                {
                    if (i >= 0)
                    {
                        radGridView1.Rows.RemoveAt(i);
                    }
                }
            }
            DataTable dt = new DataTable();
            dt = cq.loadluoicapquyen(manhom);
            if (dt.Rows.Count > 0)
            {
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    GridViewRowInfo newRow = radGridView1.Rows.NewRow();
                    newRow.Cells["ID"].Value = ClassXuLyChung.GetSafeInt(dt.Rows[j]["ID"]);
                    newRow.Cells["MaNhomUser"].Value = ClassXuLyChung.GetSafeInt(dt.Rows[j]["MaNhomUser"]);
                    newRow.Cells["MaNhomMenuND"].Value = ClassXuLyChung.GetSafeInt(dt.Rows[j]["MaNhomMenuND"]);
                    newRow.Cells["MaChuongTrinh"].Value = ClassXuLyChung.GetSafeInt(dt.Rows[j]["MaChuongTrinh"]);
                    newRow.Cells["IDViTri"].Value = ClassXuLyChung.GetSafeInt(dt.Rows[j]["IDViTri"]);
                    newRow.Cells["TenNhomUser"].Value = ClassXuLyChung.GetSafeString(dt.Rows[j]["TenNhomUser"]);
                    newRow.Cells["TenNhomMenuND"].Value = ClassXuLyChung.GetSafeString(dt.Rows[j]["TenNhomMenuND"]);
                    newRow.Cells["TenChuongTrinh"].Value = ClassXuLyChung.GetSafeString(dt.Rows[j]["TenChuongTrinh"]);
                    newRow.Cells["DienGiai"].Value = ClassXuLyChung.GetSafeString(dt.Rows[j]["DienGiai"]);
                    radGridView1.Rows.Add(newRow);
                }
            }
         //   radGridView1.DataSource = cq.loadluoicapquyen(manhom);
           
          
            
        }
        private void khoitaoluoicapquyen()
        {
            this.radGridView1.EnableHotTracking = true;
            this.radGridView1.ShowFilteringRow = false;
            this.radGridView1.EnableFiltering = true;
            this.radGridView1.MasterTemplate.ShowHeaderCellButtons = true;
            this.radGridView1.MasterTemplate.ShowFilteringRow = false;
            this.radGridView1.MasterTemplate.AutoExpandGroups = true;
            //this.radGridView1.TableElement.RowHeight = 65;
            this.radGridView1.MasterTemplate.AllowAddNewRow = false;
            this.radGridView1.MasterTemplate.AutoGenerateColumns = false;
            this.radGridView1.MasterTemplate.AllowEditRow = true;
            this.radGridView1.MasterTemplate.AllowDeleteRow = false;
            this.radGridView1.MasterTemplate.EnableSorting = true;
            this.radGridView1.MasterTemplate.AllowAutoSizeColumns = true;
            this.radGridView1.AutoScroll = true;
            this.radGridView1.EnableAlternatingRowColor = true;



            GridViewTextBoxColumn textBoxColumn0 = new GridViewTextBoxColumn()
            {
                FieldName = "ID",
                Name = "ID",
                HeaderText = "ID",
                Width = 50,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn0);

            GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn()
            {
                FieldName = "MaNhomUser",
                Name = "MaNhomUser",
                HeaderText = "ID",
                Width = 50,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn);

            GridViewTextBoxColumn textBoxColumn2 = new GridViewTextBoxColumn()
            {
                FieldName = "MaNhomMenuND",
                Name = "MaNhomMenuND",
                HeaderText = "ID",
                Width = 50,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn2);

            GridViewTextBoxColumn textBoxColumn3 = new GridViewTextBoxColumn()
            {
                FieldName = "MaChuongTrinh",
                Name = "MaChuongTrinh",
                HeaderText = "ID",
                Width = 50,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn3);

            GridViewTextBoxColumn textBoxColumn4 = new GridViewTextBoxColumn()
            {
                FieldName = "IDViTri",
                Name = "IDViTri",
                HeaderText = "ID",
                Width = 50,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn4);

            GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn()
            {
                FieldName = "TenNhomUser",
                Name = "TenNhomUser",
                HeaderText = "Nhóm User",
                Width = 300,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn1);

            GridViewTextBoxColumn textBoxColumn5 = new GridViewTextBoxColumn()
            {
                FieldName = "TenNhomMenuND",
                Name = "TenNhomMenuND",
                HeaderText = "Nhóm Menu",
                Width = 300,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn5);

            GridViewTextBoxColumn textBoxColumn6 = new GridViewTextBoxColumn()
            {
                FieldName = "TenChuongTrinh",
                Name = "TenChuongTrinh",
                HeaderText = "Module",
                Width = 300,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn6);

            GridViewTextBoxColumn textBoxColumn7 = new GridViewTextBoxColumn()
            {
                FieldName = "DienGiai",
                Name = "DienGiai",
                HeaderText = "Vị Trí Menu",
                Width = 340,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.radGridView1.Columns.Add(textBoxColumn7);

            GridViewCommandColumn CommandColumn = new GridViewCommandColumn()
            {
                HeaderText = "Xóa",
                Name = "Del",
                Width = 40,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter,

                Image = Image.FromFile(Application.StartupPath + @"\\Images\\xoa.png")
            };
            this.radGridView1.Columns.Add(CommandColumn);
        }
        private void loadgridnhommenu(int manhom)
        {
            this.gridMenuGroup.DataSource = cq.loadluoinhommenu(manhom);
        }
        private void loadgridchuongtrinh(int manhom)
        {
            this.gridModule.DataSource = cq.loadluoichuongtrinh(manhom);
        }
        private void loadgridvitri(int manhom)
        {
            this.gridLocation.DataSource = cq.loadluoivitri(manhom);
        }
        private void UpdatePanelInfo(GridViewRowInfo currentRow)
        {
            if (currentRow != null && !(currentRow is GridViewNewRowInfo))
            {
                if (currentRow.Cells[3].IsCurrent == false)
                {
                    MaNhom = ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value);
                    tennhom = ClassXuLyChung.GetSafeString(currentRow.Cells[1].Value);
                    loadgridnhommenu(ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value));
                    loadgridchuongtrinh(ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value));
                    loadgridvitri(ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value));
                    //     IDCu = ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value);
                    //txtDienGiai.Text = ClassXuLyChung.GetSafeString(currentRow.Cells[2].Value);
                }
                else
                {
                    GridViewRowInfo newRow = radGridView1.Rows.NewRow();
                    if (radGridView1.RowCount > 0)
                    {
                        if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomUser"].Value) != "" &&
                            ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomMenuND"].Value) != ""
                            && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaChuongTrinh"].Value) != ""
                            && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["IDViTri"].Value) != "")
                        {
                            newRow.Cells["MaNhomUser"].Value = ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value);
                            newRow.Cells["TenNhomUser"].Value = ClassXuLyChung.GetSafeString(currentRow.Cells[1].Value);
                            //  newRow.Cells["TenNhomUser"].Value = radTextBox2.Text;
                            radGridView1.Rows.Add(newRow);
                        }
                        else
                        {

                        //    if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomUser"].Value) == "")
                           // {
                                radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomUser"].Value = ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value);
                                radGridView1.Rows[radGridView1.RowCount - 1].Cells["TenNhomUser"].Value = ClassXuLyChung.GetSafeString(currentRow.Cells[1].Value);
                           // }
                        }
                    }
                    else
                    {
                        newRow.Cells["MaNhomUser"].Value = ClassXuLyChung.GetSafeInt(currentRow.Cells[0].Value);
                        newRow.Cells["TenNhomUser"].Value = ClassXuLyChung.GetSafeString(currentRow.Cells[1].Value);
                        radGridView1.Rows.Add(newRow);
                    }
            
                }



            }
            else
            {
                MaNhom = 0;
                tennhom = "";
                loadgridnhommenu(0);
                loadgridchuongtrinh(0);
                loadgridvitri(0);
              //  IDCu = 0;
            }
        }
        private void loaddulideunhomnguoidung()
        {
            gridUsersGroup.DataSource = cq.loadgirdnhomnguoidung();
        }
        private void khoitaogridnhomnguoidung()
        {

            this.gridUsersGroup.EnableHotTracking = true;
            this.gridUsersGroup.ShowFilteringRow = false;
            this.gridUsersGroup.EnableFiltering = true;
            this.gridUsersGroup.MasterTemplate.ShowHeaderCellButtons = true;
            this.gridUsersGroup.MasterTemplate.ShowFilteringRow = false;
            this.gridUsersGroup.MasterTemplate.AutoExpandGroups = true;
            //this.radGridView1.TableElement.RowHeight = 65;
            this.gridUsersGroup.MasterTemplate.AllowAddNewRow = false;
            this.gridUsersGroup.MasterTemplate.AutoGenerateColumns = false;
            this.gridUsersGroup.MasterTemplate.AllowEditRow = true;
            this.gridUsersGroup.MasterTemplate.AllowDeleteRow = false;
            this.gridUsersGroup.MasterTemplate.EnableSorting = true;
            this.gridUsersGroup.MasterTemplate.AllowAutoSizeColumns = true;
            this.gridUsersGroup.AutoScroll = true;
            this.gridUsersGroup.EnableAlternatingRowColor = true;

     
            GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn()
            {
                FieldName = "MaNhomUser",
                Name = "MaNhomUser",
                HeaderText = "ID",
                Width = 50,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridUsersGroup.Columns.Add(textBoxColumn);

            GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn()
            {
                FieldName = "TenNhomUser",
                Name = "TenNhomUser",
                HeaderText = "Tên Nhóm",
                Width = 135,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridUsersGroup.Columns.Add(textBoxColumn1);

            GridViewTextBoxColumn textBoxColumn2 = new GridViewTextBoxColumn()
            {
                FieldName = "DoUuTien",
                Name = "DoUuTien",
                HeaderText = "Độ Ưu Tiên",
                Width = 75,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridUsersGroup.Columns.Add(textBoxColumn2);

            GridViewCommandColumn CommandColumn = new GridViewCommandColumn()
            {
                HeaderText = "Add",
                Name = "Add",
                Width = 40,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter,

                Image = Image.FromFile(Application.StartupPath + @"\\Images\\add.png")
            };
            this.gridUsersGroup.Columns.Add(CommandColumn);
        }
       
     
        private void khoitaogridchuongtrinh()
        {

            this.gridModule.EnableHotTracking = true;
            this.gridModule.ShowFilteringRow = false;
            this.gridModule.EnableFiltering = true;
            this.gridModule.MasterTemplate.ShowHeaderCellButtons = true;
            this.gridModule.MasterTemplate.ShowFilteringRow = false;
            this.gridModule.MasterTemplate.AutoExpandGroups = true;
            //this.radGridView1.TableElement.RowHeight = 65;
            this.gridModule.MasterTemplate.AllowAddNewRow = false;
            this.gridModule.MasterTemplate.AutoGenerateColumns = false;
            this.gridModule.MasterTemplate.AllowEditRow = true;
            this.gridModule.MasterTemplate.AllowDeleteRow = false;
            this.gridModule.MasterTemplate.EnableSorting = true;
            this.gridModule.MasterTemplate.AllowAutoSizeColumns = true;
            this.gridModule.AutoScroll = true;
            this.gridModule.EnableAlternatingRowColor = true;

            CustomCheckBoxColumn checkBoxColumn = new CustomCheckBoxColumn()
            {
                HeaderText = "",
                FieldName = "Chon",
                Name = "Chon",
                Width = 30,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridModule.Columns.Add(checkBoxColumn);
            GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn()
            {
                FieldName = "MaChuongTrinh",
                Name = "MaChuongTrinh",
                HeaderText = "MaChuongTrinh",
                Width = 100,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridModule.Columns.Add(textBoxColumn);

            GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn()
            {
                FieldName = "TenChuongTrinh",
                Name = "TenChuongTrinh",
                HeaderText = "Modulde",
                Width = 180,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridModule.Columns.Add(textBoxColumn1);

            GridViewTextBoxColumn textBoxColumn2 = new GridViewTextBoxColumn()
            {
                FieldName = "DienGiai",
                Name = "DienGiai",
                HeaderText = "Module Group",
                Width = 180,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridModule.Columns.Add(textBoxColumn2);

            GridViewCommandColumn CommandColumn = new GridViewCommandColumn()
            {
                HeaderText = "Add",
                Name = "Add",
                Width = 40,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter,

                Image = Image.FromFile(Application.StartupPath + @"\\Images\\add.png")
            };
            this.gridModule.Columns.Add(CommandColumn);

        }

        private void khoitaogridnhommenu()
        {

            this.gridMenuGroup.EnableHotTracking = true;
            this.gridMenuGroup.ShowFilteringRow = false;
            this.gridMenuGroup.EnableFiltering = true;
            this.gridMenuGroup.MasterTemplate.ShowHeaderCellButtons = true;
            this.gridMenuGroup.MasterTemplate.ShowFilteringRow = false;
            this.gridMenuGroup.MasterTemplate.AutoExpandGroups = true;
            //this.radGridView1.TableElement.RowHeight = 65;
            this.gridMenuGroup.MasterTemplate.AllowAddNewRow = false;
            this.gridMenuGroup.MasterTemplate.AutoGenerateColumns = false;
            this.gridMenuGroup.MasterTemplate.AllowEditRow = true;
            this.gridMenuGroup.MasterTemplate.AllowDeleteRow = false;
            this.gridMenuGroup.MasterTemplate.EnableSorting = true;
            this.gridMenuGroup.MasterTemplate.AllowAutoSizeColumns = true;
            this.gridMenuGroup.AutoScroll = true;
            this.gridMenuGroup.EnableAlternatingRowColor = true;

            CustomCheckBoxColumn checkBoxColumn = new CustomCheckBoxColumn()
            {
                HeaderText = "",
                FieldName = "Chon",
                Name = "Chon",
                Width = 25,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridMenuGroup.Columns.Add(checkBoxColumn);
            GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn()
            {
                FieldName = "MaNhomMenuND",
                Name = "MaNhomMenuND",
                HeaderText = "MaNhomMenuND",
                Width = 100,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridMenuGroup.Columns.Add(textBoxColumn);

            GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn()
            {
                FieldName = "TenNhomMenuND",
                Name = "TenNhomMenuND",
                HeaderText = "Nhóm Menu",
                Width = 168,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridMenuGroup.Columns.Add(textBoxColumn1);

            GridViewCommandColumn CommandColumn = new GridViewCommandColumn()
            {
                HeaderText = "Add",
                Name = "Add",
                Width = 40,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter,

                Image = Image.FromFile(Application.StartupPath + @"\\Images\\add.png")
            };
            this.gridMenuGroup.Columns.Add(CommandColumn);



        }
        private void khoitaogridvitri()
        {

            this.gridLocation.EnableHotTracking = true;
            this.gridLocation.ShowFilteringRow = false;
            this.gridLocation.EnableFiltering = true;
            this.gridLocation.MasterTemplate.ShowHeaderCellButtons = true;
            this.gridLocation.MasterTemplate.ShowFilteringRow = false;
            this.gridLocation.MasterTemplate.AutoExpandGroups = true;
            //this.radGridView1.TableElement.RowHeight = 65;
            this.gridLocation.MasterTemplate.AllowAddNewRow = false;
            this.gridLocation.MasterTemplate.AutoGenerateColumns = false;
            this.gridLocation.MasterTemplate.AllowEditRow = true;
            this.gridLocation.MasterTemplate.AllowDeleteRow = false;
            this.gridLocation.MasterTemplate.EnableSorting = true;
            this.gridLocation.MasterTemplate.AllowAutoSizeColumns = true;
            this.gridLocation.AutoScroll = true;
            this.gridLocation.EnableAlternatingRowColor = true;

            CustomCheckBoxColumn checkBoxColumn = new CustomCheckBoxColumn()
            {
                HeaderText = "",
                FieldName = "Chon",
                Name = "Chon",
                Width = 25,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridLocation.Columns.Add(checkBoxColumn);
            GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn()
            {
                FieldName = "IDViTri",
                Name = "IDViTri",
                HeaderText = "IDViTri",
                Width = 100,
                IsVisible = false,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridLocation.Columns.Add(textBoxColumn);

            GridViewTextBoxColumn textBoxColumn1 = new GridViewTextBoxColumn()
            {
                FieldName = "DienGiai",
                Name = "DienGiai",
                HeaderText = "Vị Trí Menu",
                Width = 170,
                IsVisible = true,
                ReadOnly = true,
                TextAlignment = ContentAlignment.MiddleCenter
            };
            this.gridLocation.Columns.Add(textBoxColumn1);


            GridViewCommandColumn CommandColumn = new GridViewCommandColumn()
            {
                HeaderText = "Add",
                Name = "Add",
                Width = 40,
                IsVisible = true,
                TextAlignment = ContentAlignment.MiddleCenter,

                Image = Image.FromFile(Application.StartupPath + @"\\Images\\add.png")
            };
            this.gridLocation.Columns.Add(CommandColumn);

        }
        

        private void txtTimKiemUserGroup_TextChanged(object sender, EventArgs e)
        {
             
            ClassXuLyChung.tuychontimkiemtrenluoi(txtTimKiemUserGroup, gridUsersGroup, 0, 1);
        

      
        }

        private void txtTimKiemMenuGroup_TextChanged(object sender, EventArgs e)
        {
             
            ClassXuLyChung.tuychontimkiemtrenluoi(txtTimKiemMenuGroup, gridMenuGroup, 2, 1);
        

      
        }

        private void txtTimKiemModule_TextChanged(object sender, EventArgs e)
        {
             
            ClassXuLyChung.tuychontimkiemtrenluoi(txtTimKiemModule,gridModule, 2, 1);
       

      
        }

        private void txtTimKiemLoaction_TextChanged(object sender, EventArgs e)
        {
             
            ClassXuLyChung.tuychontimkiemtrenluoi(txtTimKiemLoaction,gridLocation, 2, 1);
       
        }

        private void txtTimKiem_TextChanged(object sender, EventArgs e)
        {

            ClassXuLyChung.tuychontimkiemtrenluoi(txtTimKiem, radGridView1, 2, 0);
     
        }

        private void gridUsersGroup_CellClick(object sender, GridViewCellEventArgs e)
        {
           
          
            UpdatePanelInfo(this.gridUsersGroup.CurrentRow);
        
        }

        private void btnResetRole_Click(object sender, EventArgs e)
        {
          
            if (MaNhom != 0)
            {
                DialogResult kq = RadMessageBox.Show(String.Format("Bạn có muốn chắc reset quyen \n : {0} không ???", tennhom), "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
                if (kq == DialogResult.Yes)
                {

                    if (cq.xoa(MaNhom) == 1)
                    {
                        RadMessageBox.Show("Reset Thành Công Nhóm \n : " + tennhom, "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Info);

                        loaddulideunhomnguoidung();
                        UpdatePanelInfo(this.gridUsersGroup.CurrentRow);
                    }
                    else
                    {
                        RadMessageBox.Show("nhóm này chưa được cấp quyền ", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
                    }
                }

            }
            else
            {
                RadMessageBox.Show("Không tồn tại dữ liệu ", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
            }
 
        }

        private void btnViewRole_Click(object sender, EventArgs e)
        {
          loadluoicapquyen(MaNhom);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (radGridView1.RowCount > 0)
            {
                for (int i = 0; i < radGridView1.RowCount; i++)
                {
                    cq.them(ClassXuLyChung.GetSafeInt(radGridView1.Rows[i].Cells["MaNhomUser"].Value), ClassXuLyChung.GetSafeInt(radGridView1.Rows[i].Cells["MaNhomMenuND"].Value),
                        ClassXuLyChung.GetSafeInt(radGridView1.Rows[i].Cells["MaChuongTrinh"].Value), ClassXuLyChung.GetSafeInt(radGridView1.Rows[i].Cells["IDViTri"].Value)
                        , ClassXuLyChung.GetSafeInt(radGridView1.Rows[i].Cells["ID"].Value));
                }
            }
            RadMessageBox.Show("Cập Nhật Thành Công ", "Thông Tin", MessageBoxButtons.OK, RadMessageIcon.Info);
           // UpdatePanelInfo(this.gridUsersGroup.CurrentRow);
        }

        private void gridMenuGroup_CellClick(object sender, GridViewCellEventArgs e)
        {
            if (gridMenuGroup.CurrentRow.Cells[3].IsCurrent == true)
            {
                GridViewRowInfo newRow = radGridView1.Rows.NewRow();
                if (radGridView1.RowCount > 0)
                {
                    if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomUser"].Value) != "" &&
                        ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomMenuND"].Value) != ""
                        && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaChuongTrinh"].Value) != ""
                        && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["IDViTri"].Value) != "")
                    {
                        newRow.Cells["MaNhomMenuND"].Value = ClassXuLyChung.GetSafeInt(gridMenuGroup.CurrentRow.Cells[1].Value);
                        newRow.Cells["TenNhomMenuND"].Value = ClassXuLyChung.GetSafeString(gridMenuGroup.CurrentRow.Cells[2].Value);
                        //  newRow.Cells["TenNhomUser"].Value = radTextBox2.Text;
                        radGridView1.Rows.Add(newRow);
                    }
                    else
                    {

                      //  if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomMenuND"].Value) == "")
                      //  {
                            radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomMenuND"].Value = ClassXuLyChung.GetSafeInt(gridMenuGroup.CurrentRow.Cells[1].Value);
                            radGridView1.Rows[radGridView1.RowCount - 1].Cells["TenNhomMenuND"].Value = ClassXuLyChung.GetSafeString(gridMenuGroup.CurrentRow.Cells[2].Value);
                      //  }
                       
                    }
                }
                else
                {
                    newRow.Cells["MaNhomMenuND"].Value = ClassXuLyChung.GetSafeInt(gridMenuGroup.CurrentRow.Cells[1].Value);
                    newRow.Cells["TenNhomMenuND"].Value = ClassXuLyChung.GetSafeString(gridMenuGroup.CurrentRow.Cells[2].Value);
                    radGridView1.Rows.Add(newRow);
                }
            }
        }

        private void gridModule_CellClick(object sender, GridViewCellEventArgs e)
        {
            if (gridModule.CurrentRow.Cells[4].IsCurrent == true)
            {
                GridViewRowInfo newRow = radGridView1.Rows.NewRow();
                if (radGridView1.RowCount > 0)
                {
                    if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomUser"].Value) != "" &&
                        ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomMenuND"].Value) != ""
                        && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaChuongTrinh"].Value) != ""
                        && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["IDViTri"].Value) != "")
                    {
                        newRow.Cells["MaChuongTrinh"].Value = ClassXuLyChung.GetSafeInt(gridModule.CurrentRow.Cells[1].Value);
                        newRow.Cells["TenChuongTrinh"].Value = ClassXuLyChung.GetSafeString(gridModule.CurrentRow.Cells[2].Value);
                        //  newRow.Cells["TenNhomUser"].Value = radTextBox2.Text;
                        radGridView1.Rows.Add(newRow);
                    }
                    else
                    {

                      //  if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaChuongTrinh"].Value) == "")
                       // {
                            radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaChuongTrinh"].Value = ClassXuLyChung.GetSafeInt(gridModule.CurrentRow.Cells[1].Value);
                            radGridView1.Rows[radGridView1.RowCount - 1].Cells["TenChuongTrinh"].Value = ClassXuLyChung.GetSafeString(gridModule.CurrentRow.Cells[2].Value);
                       // }
                    }
                }
                else
                {
                    newRow.Cells["MaChuongTrinh"].Value = ClassXuLyChung.GetSafeInt(gridModule.CurrentRow.Cells[1].Value);
                    newRow.Cells["TenChuongTrinh"].Value = ClassXuLyChung.GetSafeString(gridModule.CurrentRow.Cells[2].Value);
                    radGridView1.Rows.Add(newRow);
                }
            }
        }

        private void gridLocation_CellClick(object sender, GridViewCellEventArgs e)
        {
            if (gridLocation.CurrentRow.Cells[3].IsCurrent == true)
            {
                GridViewRowInfo newRow = radGridView1.Rows.NewRow();
                if (radGridView1.RowCount > 0)
                {
                    if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomUser"].Value) != "" &&
                        ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaNhomMenuND"].Value) != ""
                        && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["MaChuongTrinh"].Value) != ""
                        && ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["IDViTri"].Value) != "")
                    {
                        newRow.Cells["IDViTri"].Value = ClassXuLyChung.GetSafeInt(gridLocation.CurrentRow.Cells[1].Value);
                        newRow.Cells["DienGiai"].Value = ClassXuLyChung.GetSafeString(gridLocation.CurrentRow.Cells[2].Value);
                        //  newRow.Cells["TenNhomUser"].Value = radTextBox2.Text;
                        radGridView1.Rows.Add(newRow);
                    }
                    else
                    {

                     //   if (ClassXuLyChung.GetSafeString(radGridView1.Rows[radGridView1.RowCount - 1].Cells["IDViTri"].Value) == "")
                      //  {
                            radGridView1.Rows[radGridView1.RowCount - 1].Cells["IDViTri"].Value = ClassXuLyChung.GetSafeInt(gridLocation.CurrentRow.Cells[1].Value);
                            radGridView1.Rows[radGridView1.RowCount - 1].Cells["DienGiai"].Value = ClassXuLyChung.GetSafeString(gridLocation.CurrentRow.Cells[2].Value);
                       // }
                    }
                }
                else
                {
                    newRow.Cells["IDViTri"].Value = ClassXuLyChung.GetSafeInt(gridLocation.CurrentRow.Cells[1].Value);
                    newRow.Cells["DienGiai"].Value = ClassXuLyChung.GetSafeString(gridLocation.CurrentRow.Cells[2].Value);
                    radGridView1.Rows.Add(newRow);
                }
            }
        }

      

        private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
        {
            try
            {
                if (radGridView1.CurrentRow.Cells[9].IsCurrent == true)
                {
                    if (xoakt == 1)
                    {
                        DialogResult kq = RadMessageBox.Show("Bạn có chắc muốn xóa \n dòng được chọn không", "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
                        if (kq == DialogResult.Yes)
                        {
                            if (ClassXuLyChung.GetSafeInt(radGridView1.CurrentRow.Cells[0].Value) != 0)
                            {
                                DialogResult kq1 = RadMessageBox.Show("Dòng này đã lưu trong databse \n bạn có chắc là muốn xóa không?", "Thông Báo", MessageBoxButtons.YesNo, RadMessageIcon.Question);
                                if (kq1 == DialogResult.Yes)
                                {
                                    cq.xoadong(ClassXuLyChung.GetSafeInt(radGridView1.CurrentRow.Cells[0].Value));
                                    radGridView1.Rows.Remove(radGridView1.CurrentRow);
                                    UpdatePanelInfo(this.gridUsersGroup.CurrentRow);
                                }
                            }
                            else
                            {
                                radGridView1.Rows.Remove(radGridView1.CurrentRow);
                            }
                        }
                    }
                    else
                    {
                    }
                }
            }
            catch
            {
                return;
            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (radGridView1.RowCount > 0)
            {
                for (int i = radGridView1.RowCount - 1; i >= 0; i--)
                {
                    if (i >= 0)
                    {
                        radGridView1.Rows.RemoveAt(i);
                    }
                }
            }
        }

        private void frmCapMenuInUser_Load(object sender, EventArgs e)
        {

        }

      

   


    }
}
